package nickthissen.iracing.parsing;

import android.util.Log;

import org.apache.commons.lang3.StringEscapeUtils;

import java.net.URLDecoder;

/**
 * Created by Nick on 19-5-13.
 */
public class HttpUtil
{
    public static String htmlDecode(String html)
    {
        try
        {
            return StringEscapeUtils.unescapeHtml4(html);
        }
        catch (Exception ex)
        {
            Log.e("HttpUtil", "Error decoding HTML '" + html + "': " + ex.getMessage());
            return html;
        }
    }

    public static String htmlEncode(String text)
    {
        try
        {
            return StringEscapeUtils.escapeHtml4(text);
        }
        catch (Exception ex)
        {
            Log.e("HttpUtil", "Error encoding text '" + text + "': " + ex.getMessage());
            return text;
        }
    }

    public static String urlDecode(String html)
    {
        try
        {
            return URLDecoder.decode(html, "UTF-8");
        }
        catch (Exception ex)
        {
            Log.e("HttpUtil", "Error decoding URL '" + html + "': " + ex.getMessage());
            return html;
        }
    }
}
